#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e6+50;
int t,n,a[MAXN];
int color[MAXN],ans,maxn=-1;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>n;
        memset(color,0,sizeof(color));
        ans=0;
        for(int j=1;j<=n;j++){
            cin>>a[j];
            color[a[j]]++;
            maxn=max(a[j],maxn);
        }
        for(int j=1;j<=maxn;j++){
            if(color[j]>1){
                ans+=j*color[j]/2;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
